﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace OntoWPFSilverlight.Widget
{
    public class CustomButton : Button , Interfaces.IWidget
    {
        Xml.WidgetLocation widgetLocation = null;
        Xml.WidgetSize widgetSize = null;
        Xml.WidgetFont widgetFont = null;
        Xml.Appearance appearance = null;

        string widgetParent;
        string type;
        
        
        public CustomButton()
        {
            this.Build();
        }

        private void Build()
        {
            
        }
        
        
        
        #region IWidget Membri di

        public Xml.WidgetLocation  WidgetLocation
        {
            get
            {
                //return widgetLocation == null ? new Xml.WidgetLocation(Int32.Parse(base.GetValue(LeftProperty).ToString()), Int32.Parse(base.GetValue(TopProperty).ToString()), "", "") : widgetLocation;
                return widgetLocation;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter location");
                widgetLocation = value;
                Canvas.SetLeft(this, widgetLocation.X);
                Canvas.SetTop(this, widgetLocation.Y);
            }
        }

        public Xml.WidgetSize WidgetSize
        {
            get
            {
                return widgetSize == null ? new Xml.WidgetSize(Int32.Parse(this.GetValue(WidthProperty).ToString()), Int32.Parse(this.GetValue(HeightProperty).ToString())) : widgetSize;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter size");
                widgetSize = value;
                this.Height = widgetSize.Height;
                this.Width = widgetSize.Width;
            }
        }

        public Xml.WidgetFont WidgetFont
        {
            get
            {
                return widgetFont;
            }
            set
            {
                widgetFont = value;
            }
        }

        public Xml.Appearance Appearance
        {
            get
            {
                return appearance == null ? new Xml.Appearance(base.GetValue(BackgroundProperty).ToString(), "", base.GetValue(CursorProperty).ToString()) : appearance;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter appareance");
                appearance = value;
                byte r, g, b;
                byte.TryParse(appearance.BackColor.Split(',')[0], out r);
                byte.TryParse(appearance.BackColor.Split(',')[1], out g);
                byte.TryParse(appearance.BackColor.Split(',')[2], out b);
                this.Background = new SolidColorBrush(Color.FromArgb(255, r, g, b));
            }
        }

        public string Name
        {
            get
            {
                return base.Name;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter name ");
                //this.Name = value;
                base.Name = value;
            }
        }

        public string WidgetParent
        {
            get
            {

                return widgetParent == null ? base.Parent.ToString() : widgetParent;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter parent");
                widgetParent = value;
            }
        }

        public string Type
        {
            get
            {
                return type == null ? base.GetType().ToString() : type;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter type");
                type = value;
            }
        }

        public string Text
        {
            get
            {
                return Content == null ? base.Content.ToString() : Content.ToString();
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter content" + value);
                this.Content = value;
            }
        }

        #endregion
    }
}
